package zanalytics

type AnalyticsFilters struct {
	// 白名单
	Usernames []string `json:"usernames"`
	// 黑名单
	SkippedUsernames []string `json:"skip_usernames"`
}

func (f AnalyticsFilters) ShouldFilter(r AnalyticsRecord) bool {
	switch {
	case len(f.SkippedUsernames) > 0 && stringInSlice(r.Username, f.SkippedUsernames):
		return true
	case len(f.Usernames) > 0 && !stringInSlice(r.Username, f.Usernames):
		return true
	}

	return false
}

func (f AnalyticsFilters) HasFilter() bool {
	if len(f.SkippedUsernames) == 0 && len(f.Usernames) == 0 {
		return false
	}
	return true
}

func stringInSlice(a string, list []string) bool {
	for _, b := range list {
		if a == b {
			return true
		}
	}
	return false
}
